package nio.bytebuffer;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

/**
 * StringToByteBufferDemo
 *
 * @author chenxin
 * @date 2022/05/14 18:05
 **/
public class StringToByteBufferDemo {

    public static void main(String[] args) {

        ByteBuffer byteBuffer = ByteBuffer.allocate(16);
        byteBuffer.put("hello".getBytes(StandardCharsets.UTF_8));
        System.out.println(byteBuffer);

        ByteBuffer buffer = ByteBuffer.wrap("hello".getBytes(StandardCharsets.UTF_8));
        System.out.println(buffer);

        ByteBuffer buffer1 = StandardCharsets.UTF_8.encode("hello");
        System.out.println(buffer1);

    }

}